Visualizing `==`, `!=`, `===`, and `!==`.
Loose equality checks if two values are equal, but it performs **type coercion** before the comparison. This means it will try to convert operands to a common type (e.g., number) before checking for equality.
5 == "5"; // true "true" == true; // true
Expression: `5 == "5"`
Result:
Expression: `null == undefined`
Result:
Expression: `0 == false`
Result:
Expression: `10 != "10"`
Result:
Expression: `null != undefined`
Result:
Expression: `0 != false`
Result:
Strict equality checks if two values are equal **without** performing any type coercion. If the values are of different types, they are considered unequal. This is the recommended practice to avoid unexpected behavior.
5 === "5"; // false 1 === true; // false
Expression: `5 === "5"`
Result:
Expression: `1 === true`
Result:
Expression: `null === undefined`
Result:
Expression: `10 !== "10"`
Result:
Expression: `1 !== true`
Result:
Expression: `null !== undefined`
Result: